package com.maykk.Demo05;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @ClassName: Demo05Test
 * @Description: TODO
 * @Author: MaykkStar@163.com
 */
public class Demo05Test {
    public static void main(String[] args) throws SQLException {
        String name = "马一坤";
        // 根据姓名查询学生
        findByName(name);
    }

    private static void findByName(String name) throws SQLException {
        final String SQL = "select id, name, sex, age, score, tel, classid from stu where name=?";
        JdbcUtilsSing jdbc = JdbcUtilsSing.getInstance();
        Connection conn = jdbc.getConnection();
        PreparedStatement pst = conn.prepareStatement(SQL);
        pst.setString(1, name);
        ResultSet rs = pst.executeQuery();
        showRes(rs);
        jdbc.free(rs, pst, conn);
    }

    public static void showRes(ResultSet rs) throws SQLException {
        while (rs.next()) {
            System.out.println(
                            rs.getString("name") + "\t" +
                            ((rs.getInt("sex") == 1) ? "男" : "女") + "\t" +
                            rs.getInt("age") + "\t" +
                            rs.getFloat("score") + "\t" +
                            rs.getString("tel") + "\t" +
                            rs.getString("classid")
            );
        }
    }
}
